using System;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace RealDolmen.SharePoint.EventReceivers
{
    public class CopyAppBinContentFeatureReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            CopyAppBinContent();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
        }

        public static void CopyAppBinContent()
        {
            SPServiceInstance localContent = SPWebServiceInstance.LocalContent;
            if ((localContent != null) && (localContent.Status == SPObjectStatus.Online))
            {
                SPWebService.ContentService.ApplyApplicationContentToLocalServer();
            }
            localContent = SPWebServiceInstance.LocalAdministration;
            if ((localContent != null) && (localContent.Status == SPObjectStatus.Online))
            {
                SPWebService.AdministrationService.ApplyApplicationContentToLocalServer();
            }
        }
    }
}
